package com.prs.crm.domain.sys;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;

import com.prs.crm.domain.BaseEntity;


@Entity
@Table(name="sys_module")
public class Module extends BaseEntity{

	/**
	 * 
	 */
	private static final long serialVersionUID = 8357063857642456988L;

	@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer id;
	
	private String name;
	
	@OneToMany(mappedBy="module", fetch = FetchType.LAZY,cascade ={CascadeType.ALL,CascadeType.REMOVE})
	@OrderBy
	@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
	private Set<UIResource> resources;
	
	private String remark;

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getId() {
		return id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setResources(Set<UIResource> resources) {
		this.resources = resources;
	}

	public Set<UIResource> getResources() {
		return resources;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getRemark() {
		return remark;
	}
	
	public void addResource(UIResource resource)
	{
		this.getResources().add(resource);
		resource.setModule(this);
	}
}
